import React from "react";

/** 带有状态的组件 */
class StateComponent extends React.Component {
    state = {
        count: this.props.start
    }
    componentDidMount() {
        setInterval(() => {
            this.setState({count: this.state.count + 1 })
        },1000)
    }
    componentDidUpdate(prevProps, prevState, snapshot) {
        // 到达指定数值重置计时器
        if(prevState.count === 20) {
            this.setState({count: 0})
        }
    }
    render() {
        return (
            <h3>⏲ : { this.state.count } </h3>
        )
    }
} 

export default StateComponent